<template>
  <div class="app-container">
    <el-card>
      <h3 slot="header" ref="adminHeader">管理员详情信息</h3>
      <el-form label-width="120px" :model="admin" ref="adminForm">
        <el-form-item label="账号：" prop="name">
          <el-input placeholder="请输入..." v-model="admin.username"/>
        </el-form-item>

        <el-form-item label="真实名称：" prop="name">
          <el-input placeholder="请输入..." v-model="admin.nickName"/>
        </el-form-item>
        <el-form-item label="密码：" prop="name">
          <el-tooltip placement="top-start">
            <div slot="content">当前展示的密码是加密后的密码<br/>修改信息时需要重新设置密码！！！！！！</div>
            <el-input placeholder="请输入..." v-model="admin.password"/>
          </el-tooltip>
        </el-form-item>

        <el-form-item label="邮箱：" prop="name">
          <el-input placeholder="请输入..." v-model="admin.email"/>
        </el-form-item>

        <el-form-item label="备注：" prop="originalPrice">
          <el-input placeholder="请输入..." v-model="admin.note" type="textarea" rows="5"/>
        </el-form-item>
        <el-form-item label>
          <div class="btn-box flex">
            <el-button
              plain round
              type="primary"
              ref="adminAddButton"
              size="medium"
              :disabled="isAble"
              v-text="btnText"
              v-show="isShow"
              @click="onSubmit"></el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
    import {adminUpdate} from '@/api/admin'

    const defaultData = {};

    export default {
        name: "adminDetail",
        data() {
            return {
                isShow: true,
                btnText: null,
                listLoading: true,
                logisticsDialogVisible: false,
                admin: null
            }
        },
        created() {
            this.getUrlParams();
        },
        filters: {
            formatStatus(status) {
                if (status === 1) {
                    return '启用中';
                } else {
                    return '已禁用';
                }
            }
        },
        // 页面加载完成以后执行
        mounted() {
            // console.log(this.$refs.adminAddButton);
        },
        methods: {
            getUrlParams() {
                // 取到路由带过来的参数
                this.admin = this.$route.query;
                console.log(this.$route.query.type);
                if (undefined == this.admin.type) {
                    this.btnText = '新增管理员信息';
                    this.isShow = true;
                    this.$notify({
                        title: '通知',
                        message: '添加新的数据',
                        type: 'success',
                        duration: 2000 // 是否自动关闭页面
                    });
                } else if (0 == this.admin.type) {
                    this.isShow = false;
                    this.$notify({
                        title: '通知',
                        message: '查询',
                        type: 'success',
                        duration: 2000 // 是否自动关闭页面
                    });
                } else {
                    this.btnText = '修改管理员信息';
                    this.isShow = true;
                    this.$notify({
                        title: '通知',
                        message: '修改',
                        type: 'success',
                        duration: 2000 // 是否自动关闭页面
                    });
                }
            },
            onSubmit() {
                let params = new URLSearchParams();
                console.log( "id:" +this.admin.id);
                params.append('id', this.admin.id);
                adminUpdate(this.admin.id,this.admin).then(response => {
                    this.$message({
                        message: '修改成功',
                        type: 'success',
                        duration: 1000
                    });
                });
            }
        }
    }
</script>

<style>

</style>
